package 
{
	import fgame.controller.Controller;
	import fgame.graphic.Graphic;
	import fgame.unit.Actor3D;
	
	import flare.core.Pivot3D;
	
	import net.SocketProxy;
	import net.WorkQueue;

	
	
	/**
	 * 消息与协议</br>		
	 */
	public class MsgHelper
	{
		public function MsgHelper()
		{
			
		}
		
		public static function connect(host:String,port:int):void
		{
			SocketProxy.connect(host,port);
		}
		
		/**
		 * 发送消息到服务端
		 */
		public static function sendMsgToS(msg:Object):void
		{
			if(SocketProxy.connected)
				SocketProxy.send(msg);
		}
		
		
		/**
		 * 发送消息给自己
		 */
		public static function sendMe(msg:Object):void
		{
			WorkQueue.instance.pushRecive(msg);
		}
		
		/**
		 * 发送Act消息到服务端
		 */
		public static function sendActMsg(heroName:String,actType:int,args:Object,msgType:int=10):void
		{
		
			var act:Object=new Object();
			act["name"]=heroName;
			act["type"]=actType;
			act["args"]=args;
			
			var msg:Object=new Object();
			msg["cmd"]="act";
			msg["arg"]=act;
			
			if(msgType==11) //11表示不广播给自己
			{
				sendMe(msg);
			}
			
			var smsg:Object=new Object();
			smsg["cmd"]="Room";
			smsg["t"]=msgType;//广播
			smsg["arg"]=msg;
			sendMsgToS(smsg);
		}
		
		public static function showTips(str:String):void
		{
			var msg:Object=new Object();
			msg["cmd"]="showTips";
			msg["arg"]=str;
			WorkQueue.instance.pushRecive(msg);
		}
		
		/**
		 * 同步我的位置
		 */
		public static function synchrostep():void
		{
//			var msg:Object=new Object();
//			var target:Pivot3D=Controller.instance.graphic;
//			var pos:Object={"x":target.x,"y":target.y,"z":target.z,"rotateY":target.getRotation().y};
//			
//			sendMsgToS({"cmd":"Pub","type":21,"pos":pos});
		}
		
		
		/** 网络延时 */
		public static var netDelay:int=10;
		
		
		
	}
}